const glob = require('glob');
const fs = require('fs');

glob("dzq-default-web-static/**/*.css", (err, files) => {
    if (err) {
        console.error(err);
        return;
    }

    for (let file of files) {
        fs.readFile(file, { encoding: 'utf-8' }, (err, data) => {
            if (err) {
                console.error(err);
                return;
            }
            console.log('Processing: ' + file);
            let retData = data.replace(/env\(/g, 'var(--').replace(/constant\(/g, 'var(--');
            if (retData != data) {
                fs.writeFile(file, retData, (err) => {
                    if (err) {
                        console.error(err);
                        return;
                    }
                    console.log('Generated: ' + file);
                });
            } else {
                console.log('No changes on: ' + file);
            }
        });
    }
});
